﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using FrenzDenWebSite.Business;
using System.Collections;
using System.Xml.Linq;
using System.IO;

namespace FrenzDenWebSite
{
    /// <summary>
    /// Summary description for FdService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class FdService : System.Web.Services.WebService
    {

        [WebMethod]
        public string GetProfiles(string tag)
        {
            string result = string.Empty;
            using (DenStoreDataContext dataContext = new DenStoreDataContext())
            {
                var queryResult = dataContext.SuggestProfiles(tag);

                foreach (var item in queryResult)
                {
                    result += "{" + string.Format("\"key\": \"{0}\", \"value\": \"{1}\"", item.ProfileID, item.FullName) + "}, ";
                }

                result = result.Remove(result.LastIndexOf(", "));
            }

            return "[" + result + "]";
        }

        [WebMethod]
        public bool SendMessage(string input, string message)
        {
            bool result = false;

            try
            {
                List<string> splitstr = input.Split(';').ToList<string>();
                List<string> inputIds = new List<string>();

                foreach (string item in splitstr)
                {
                    inputIds.Add(item);
                }

                result = true;
            }
            catch (Exception ex)
            {
                SiteCommon.LogError("SendMessage", ex.ToString());
            }

            return result;
        }
    }
}
